﻿ 
#include "ksstr.h"
 

#pragma warning(push)
#pragma warning ( disable : 4996 )
#pragma warning ( disable : 4290 ) 

namespace ksstr
{
  
	/*
void removeEmptyLines(std::vector<std::string>& lines)
{
	std::vector<std::string> temp = lines;
	lines.clear();
	
	for(size_t c=0; c<temp.size(); c++)
	{
		if( ! temp[c].empty() )
		{
			lines.push_back(temp[c]);
		}
	}

} 
*/
 
#ifdef WIN32




 
std::string convertWstringToAstringWinapi(const  std::wstring& src  )	 throw (std::runtime_error)
{
	if( src.length() < 1024 )
	{
		char temp[1048];
		temp[0] = '\0';

		int winapires = WideCharToMultiByte( CP_ACP, 0, src.c_str(), -1, temp, 1048, NULL, NULL );
		if(winapires==0)
		{
			throw std::runtime_error("Error call WideCharToMultiByte");
		}		
		
	
		return std::string(temp);
	}

	
	char* temp = new char [ src.length() + 16 ];

	int winapires = WideCharToMultiByte( CP_ACP, 0, src.c_str(), -1, temp, (int)(src.length() + 8), NULL, NULL );
	if(winapires == 0)
	{
		delete [] temp;
		throw std::runtime_error("Error call WideCharToMultiByte");
	}

	std::string res(temp);
	delete [] temp;
	return res;
}






 
std::wstring convertAstringToWstringWinapi( const std::string& src ) 	 throw (std::runtime_error) 
{
	if( src.length() < 1024 )
	{
		wchar_t temp[1048];
		temp[0] = L'\0';

		int winapires = MultiByteToWideChar( CP_ACP, 0, src.c_str(), (int)(src.length()+1), temp,  1048 );
		if(winapires==0)
		{
			throw std::runtime_error("Error call MultiByteToWideChar");
		}

		return std::wstring(temp);
	}

	wchar_t* temp = new wchar_t [ src.length() + 32 ];
																				 
    int winapires = MultiByteToWideChar( CP_ACP, 0, src.c_str(), (int)(1 + (int)src.length() ),  temp,  (int)(src.length() + 16)  );
	if(winapires==0)
	{
		delete [] temp;
		throw std::runtime_error("Error call MultiByteToWideChar");
	}

	std::wstring res (temp);
	delete [] temp;
	return res;
}




#endif // win32  
  



//=========================================================

void trimStrings(std::vector<std::string>& a)
{
	for(size_t c=0; c<a.size(); c++)
	{
		trim(a.at(c));
	}
}


 
} 


#pragma warning(pop)
